<template>
  <div class="app-container">
    <div class="filter-container">
      <el-button class="filter-item" type="primary" icon="el-icon-plus" @click="handleCreate">添加行业类别</el-button>
    </div>
    <el-table
      :data="data"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
    >
      <!-- <el-table-column prop="id" label="序号" width='100' align='center'/> -->
      <el-table-column prop="type_name" label="行业名称" align='center'/>
      <el-table-column prop="sort" label="排序" align='center'/>
      <el-table-column label="是否显示" width='200px' align='center'>
        <template slot-scope="item">
          <el-switch
            v-model="item.row.is_show"
            :active-value="1"
            :inactive-value="0"
            :active-text="item.row.is_show==1?'显示':'不显示'"
            @change="editItem(item.row)"
          />
        </template>
      </el-table-column>
      <el-table-column label="操作" align='center'>
        <template slot-scope="item">
          <el-link type="primary" class="table_btn" @click="handleUpdate(item.row)" :underline="false"><i class="iconfont icon-bianji"></i>编辑</el-link>
          <el-link type="danger" class="table_btn" @click="handleDelete(item.row.id)" :underline="false"><i class="iconfont icon-lajitong1"></i>删除</el-link>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      class="pagination-container"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="paginate.current"
      :hide-on-single-page='isHideSingle'
      :page-sizes="paginate.sizes"
      :page-size="paginate.limit"
      :layout="paginate.layout"
      :total="paginate.total"/>
    <el-dialog  :visible.sync="formVisible" width='500px' :show-close='false'>
      <div slot="title" class="dialog-title">{{id?'修改行业类别':'添加行业类别'}}</div>
      <el-form :model="formFieldsData" :label-position="labelPosition" :ref='formName' label-width='100px' :rules='rules'>
        <el-form-item label="行业名称：" prop='type_name'>
          <el-input v-model="formFieldsData.type_name" autocomplete="off" placeholder='请输入行业名称'></el-input>
        </el-form-item>
        <el-form-item label="排序：" prop='sort'>
          <el-input v-model.number="formFieldsData.sort" type='number' autocomplete="off" placeholder='请输入排序'></el-input>
        </el-form-item>
        <el-form-item label="是否显示：" prop='is_show'>
          <el-radio-group v-model="formFieldsData.is_show">
            <el-radio :label="1">显示</el-radio>
            <el-radio :label="0">不显示</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancel" size='medium'>取 消</el-button>
        <el-button type="primary" @click="handleSubmit" size='medium'>确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import formOperate from '@/layout/mixin/formOperate'
export default {
  name: 'Index',
  mixins: [formOperate],
  data() {
    return {
      url:'/promotion/admin/ProfessoinType',
      queryParam: {
        page:1,
        page_size:10
      },
      formName:'add',
      formFieldsData:{
        type_name:'',
        sort:1,
        is_show:1
      },
      rules:{
        type_name:[
          { required: true, message: '请输入行业名称', trigger: 'blur' }
        ],
        sort:[
          { required: true, type:'number', message: '请输入排序', trigger: 'blur' }
        ]
      },
    }
  },
  methods: {
    // 修改显示状态
    editItem(item) {
      let param = {
        is_show:item.is_show
      }
      this.$http.put(this.url + '/' + item.id, param).then((response) => {
        this.handleResponse(response)
      })
    }
  }
}
</script>
